<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>四川省考职位筛选</title>
  <style>
    table {
      width: 100%;
      border-collapse: collapse;
    }

    th,
    td {
      border: 1px solid #ddd;
      /* padding: 8px; */
    }

    th {
      background-color: #f2f2f2;
      text-align: left;
    }

    td {
      font-size: 12px;
    }

    /* td {
      max-width: 200px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    } */
    select[multiple] {
      width: 100px;
      height: 100px;
      padding: 8px;
      border: 1px solid #ddd;
      border-radius: 4px;
    }

    .title {
      font-size: 18px;
      font-weight: 500;
    }
  </style>
</head>

<body>
  <h1>2025四川省考职位筛选</h1>
  <form id="filter-form">
    <!-- <label for="department">部门:</label>
    <input type="text" id="department" name="department"><br><br>
    <label for="location">地点:</label>
    <input type="text" id="location" name="location"><br><br> -->
    <div>
      <label class="title">等级:</label><br>
      <label><input type="radio" name="dengji" value="Sheet1" checked>Sheet1</label>
    </div><br>
    <div>
      <label class="title">地点:</label><br>
      <label><input type="checkbox" name="location" value="四川省">四川省</label>
      <label><input type="checkbox" name="location" value="达州">达州</label>
    </div>
    <button onclick="selectAllDidian();return false;">全选</button>
    <button onclick="clearAllDidian();return false;">清空</button>
    <br><br><br>
    <div>
      <label class="title">招录对象:</label><br>
      <label><input type="checkbox" name="duixiang" value="社会" checked>社会</label>
      <label><input type="checkbox" name="duixiang" value="基层" checked>基层</label>
      <label><input type="checkbox" name="duixiang" value="应届">应届</label>
    </div><br>
    <div>
      <label class="title">学历:</label><br>
      <!-- <label><input type="checkbox" name="xueli" value="不限" checked>不限</label> -->
      <label><input type="checkbox" name="xueli" value="本科" checked>本科</label>
      <label><input type="checkbox" name="xueli" value="专科" checked>专科</label>
    </div><br>
    <div>
      <label class="title">专业:</label><br>
      <label><input type="checkbox" name="benke_zhuanye" value="不限">不限</label>
      <label><input type="checkbox" name="benke_zhuanye" value="空白">空白</label>
      <br>
      <label><input type="checkbox" name="benke_zhuanye" value="工学">工学</label>
      <label><input type="checkbox" name="benke_zhuanye" value="计算机类">计算机类</label>
      <label><input type="checkbox" name="benke_zhuanye" value="软件工程">软件工程</label>
      <br>
      <label><input type="checkbox" name="benke_zhuanye" value="医学">医学</label>
      <label><input type="checkbox" name="benke_zhuanye" value="护理">护理</label>
      <br>
      <label><input type="checkbox" name="benke_zhuanye" value="音乐">音乐</label>
    </div>
    <button onclick="selectAllBkzy();return false;">全选</button>
    <button onclick="clearAllBkzy();return false;">清空</button>
    <br><br><br>
    <div>
      <label class="title">备注排除:</label><br>
      <label><input type="checkbox" name="paichu_beizhu" value="国有企事业单位" checked>国有企事业单位</label>
      <label><input type="checkbox" name="paichu_beizhu" value="2025届" checked>2025届</label>
      <label><input type="checkbox" name="paichu_beizhu" value="限应届" checked>限应届</label>
      <label><input type="checkbox" name="paichu_beizhu" value="应届高校毕业生" checked>应届高校毕业生</label>
      <label><input type="checkbox" name="paichu_beizhu" value="四级" checked>英语四级</label>
      <label><input type="checkbox" name="paichu_beizhu" value="六级" checked>英语六级</label>
      <label><input type="checkbox" name="paichu_beizhu" value="女性" checked>女性</label>
    </div><br>
    <div>
      <label class="title">服务基层排除:</label><br>
      <label><input type="checkbox" name="paichu_jiceng" value="大学生村官" checked>大学生村官</label>
      <label><input type="checkbox" name="paichu_jiceng" value="三支一扶" checked>三支一扶</label>
      <label><input type="checkbox" name="paichu_jiceng" value="军队服役" checked>军队服役</label>
    </div><br>
    <div>
      <label class="title">排序:</label><br>
      <label><input type="radio" name="sortby" value="__EMPTY_11" checked>招考人数倒序</label>
      <label><input type="radio" name="sortby" value="jingzhengbi">竞争比正序</label>
    </div><br>
    <button type="button" onclick="filterPositions()">筛选</button>
  </form>
  <div id="count"></div>
  <br>
  <table id="positions-table">
    <thead>
      <tr>
        <th>系统</th>
        <th>地市</th>
        <th>职位编码</th>
        <th>地区、部门</th>
        <th>招录机关</th>
        <th>内设机构</th>
        <th>机构性质</th>
        <th>职位名称</th>
        <th>职位类别</th>
        <th>职位简介</th>
        <th>拟任职务</th>
        <th>招录名额</th>
        <th>考录范围</th>
        <th>考录对象</th>
        <th>学历</th>
        <th>学位</th>
        <th>专业</th>
        <th>政治面貌</th>
        <th>笔试开考比例</th>
        <th>面试开考比例</th>
        <th>笔试、面试成绩占比</th>
        <th>笔试加试科目一（专业科目）</th>
        <th>笔试加试科目二（少数民族语言）</th>
        <th>笔试加试科目三（心理素质测试）</th>
        <th>是否开展体能测评</th>
        <th>考察比例</th>
        <th>其他要求</th>
        <th>单位驻地是否在少数民族自治州、自治县</th>
        <th>咨询电话</th>
        <th>备注</th>
        <th>资格审查单位</th>
      </tr>
    </thead>
    <tbody>
    </tbody>
  </table>
  <script>
    async function filterPositions() {
      // const department = document.getElementById('department').value;
      // const location = document.getElementById('location').value;
      // const departmentSelect = document.getElementById('department');
      // const locationSelect = document.getElementById('location');

      // const department = Array.from(departmentSelect.selectedOptions, option => option.value);
      // const location = Array.from(locationSelect.selectedOptions, option => option.value);
      // const departmentCheckboxes = document.querySelectorAll('input[name="department"]:checked');
      // 地点
      const locationCheckboxes = document.querySelectorAll('input[name="location"]:checked');
      // 专业
      const zhuankeZhuanyeCheckboxes = document.querySelectorAll('input[name="zhuanke_zhuanye"]:checked');
      const benkeZhuanyeCheckboxes = document.querySelectorAll('input[name="benke_zhuanye"]:checked');
      // 学历
      const xueliCheckboxes = document.querySelectorAll('input[name="xueli"]:checked');
      // 等级
      const dengjiRadio = document.querySelector('input[name="dengji"]:checked');
      // 排除备注
      const paichu_beizhuCheckboxes = document.querySelectorAll('input[name="paichu_beizhu"]:checked');
      // const department = Array.from(departmentCheckboxes, checkbox => checkbox.value);
      // 服务基层排序
      const paichu_jicengCheckboxes = document.querySelectorAll('input[name="paichu_jiceng"]:checked');

      // 排序
      const sortbyRadio = document.querySelector('input[name="sortby"]:checked');
      const duixiangCheckboxes = document.querySelectorAll('input[name="duixiang"]:checked');

      const location = Array.from(locationCheckboxes, checkbox => checkbox.value);

      const zhuankeZhuanye = Array.from(zhuankeZhuanyeCheckboxes, checkbox => checkbox.value);
      const benkeZhuanye = Array.from(benkeZhuanyeCheckboxes, checkbox => checkbox.value);
      const xueli = Array.from(xueliCheckboxes, checkbox => checkbox.value);
      const dengji = dengjiRadio ? dengjiRadio.value : '';
      const paichu_beizhu = Array.from(paichu_beizhuCheckboxes, checkbox => checkbox.value);
      const paichu_jiceng = Array.from(paichu_jicengCheckboxes, checkbox => checkbox.value);
      const duixiang = Array.from(duixiangCheckboxes, checkbox => checkbox.value);
      
      const sortby = sortbyRadio ? sortbyRadio.value : '';
      const paichu = {};
      if (Array.isArray(paichu_beizhu) && paichu_beizhu.length) {
        paichu.__EMPTY_21 = paichu_beizhu;
      }
      if (Array.isArray(paichu_jiceng) && paichu_jiceng.length) {
        paichu.__EMPTY_16 = paichu_jiceng;
      }
      const response = await fetch('/api/scsk', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({
          dengji,
          qita: {
            __EMPTY_4: location, __EMPTY_16: benkeZhuanye, __EMPTY_14: xueli, __EMPTY_13: duixiang
          },
          paichu,
        })
      });

      const positions = await response.json();
      const data = sortby ? positions.sort((x, y) => Number(y[sortby]) - Number(x[sortby])) : positions;
      // const filterData = positions.filter(item => item.__EMPTY_10 > 1)
      displayPositions(positions);
      const count = document.getElementById('count');
      count.innerHTML = `已筛选出 ${positions.length} 条职位`; //,大于1人的职位${filterData.length}条`;
    }

    function displayPositions(positions) {
      const tbody = document.querySelector('#positions-table tbody');
      tbody.innerHTML = '';
      for (let i = 0; i < positions.length; i++) {
        const position = positions[i];
        const row = document.createElement('tr');
        row.innerHTML = `
          <td>${position.__EMPTY || ''}</td>
          <td>${position.__EMPTY_1 || ''}</td>
          <td>${position.__EMPTY_2 || ''}</td>
          <td>${position.__EMPTY_3 || ''}</td>
          <td>${position.__EMPTY_4 || ''}</td>
          <td>${position.__EMPTY_5 || ''}</td>
          <td title="${position.__EMPTY_6}">${position.__EMPTY_6 || ''}</td>
          <td>${position.__EMPTY_7 || ''}</td>
          <td>${position.__EMPTY_8 || ''}</td>
          <td>${position.__EMPTY_9 || ''}</td>
          <td>${position.__EMPTY_10 || ''}</td>`
          // <td>${position.baokaorenshu}</td>
          // <td>${position.guoshenrenshu}</td>
          // <td>${position.jingzhengbi}</td>
          + `<td title="${position.__EMPTY_11}">${position.__EMPTY_11 || ''}</td>
          <td>${position.__EMPTY_12 || ''}</td>
          <td>${position.__EMPTY_13 || ''}</td>
          <td>${position.__EMPTY_14 || ''}</td>
          <td>${position.__EMPTY_15 || ''}</td>
          <td>${position.__EMPTY_16 || ''}</td>
          <td>${position.__EMPTY_17 || ''}</td>
          <td>${position.__EMPTY_18 || ''}</td>
          <td>${position.__EMPTY_19 || ''}</td>
          <td>${position.__EMPTY_20}</td>
          <td title="${position.__EMPTY_21}">${position.__EMPTY_21 || ''}</td> 
          <td>${position.__EMPTY_22 || ''}</td>
          <td>${position.__EMPTY_23 || ''}</td>
          <td>${position.__EMPTY_24 || ''}</td>
          <td>${position.__EMPTY_25 || ''}</td>
          <td>${position.__EMPTY_26 || ''}</td>
          <td>${position.__EMPTY_27 || ''}</td>
          <td>${position.__EMPTY_28 || ''}</td>
          <td>${position.__EMPTY_29 || ''}</td>
          <td>${position.__EMPTY_30 || ''}</td>
          `
        tbody.appendChild(row);
      }
      // positions.forEach(position => {
      //   const row = document.createElement('tr');
      //   row.innerHTML = `
      //     <td>${position['2025年度山东省省级机关及其直属机构考试录用公务员职位表']}</td>
      //     <td>${position.__EMPTY}</td>
      //     <td>${position.__EMPTY_1}</td>
      //     <td>${position.__EMPTY_2}</td>
      //     <td>${position.__EMPTY_3}</td>
      //     <td>${position.__EMPTY_4}</td>`
      //     // <td>${position.__EMPTY_5}</td>
      //     +`<td title="${position.__EMPTY_6}">${position.__EMPTY_6}</td>
      //     <td>${position.__EMPTY_7}</td>
      //     <td>${position.__EMPTY_8}</td>
      //     <td>${position.__EMPTY_9}</td>
      //     <td>${position.__EMPTY_10}</td>
      //     <td>${position.baokaorenshu}</td>
      //     <td>${position.guoshenrenshu}</td>
      //     <td>${position.jingzhengbi}</td>
      //     <td title="${position.__EMPTY_11}">${position.__EMPTY_11}</td>
      //     <td>${position.__EMPTY_12}</td>
      //     <td>${position.__EMPTY_13}</td>
      //     <td>${position.__EMPTY_14}</td>
      //     <td>${position.__EMPTY_15}</td>
      //     <td>${position.__EMPTY_16}</td>
      //     <td>${position.__EMPTY_17}</td>
      //     <td>${position.__EMPTY_18}</td>
      //     <td>${position.__EMPTY_19}</td>
      //     <td>${position.__EMPTY_20}</td>
      //     <td title="${position.__EMPTY_21}">${position.__EMPTY_21}</td> 
      //     `
      //     // <td>${position.__EMPTY_22}</td>
      //     // <td>${position.__EMPTY_23}</td>

      //   tbody.appendChild(row);
      // });
    }

    function selectAllDidian() {
      const checkboxes = document.getElementsByName('location');
      checkboxes.forEach(checkbox => checkbox.checked = true);
    }

    function clearAllDidian() {
      const checkboxes = document.getElementsByName('location');
      checkboxes.forEach(checkbox => checkbox.checked = false);
    }

    function selectAllZkzy() {
      const checkboxes = document.getElementsByName('zhuanke_zhuanye');
      checkboxes.forEach(checkbox => checkbox.checked = true);
    }

    function clearAllZkzy() {
      const checkboxes = document.getElementsByName('zhuanke_zhuanye');
      checkboxes.forEach(checkbox => checkbox.checked = false);
    }

    function selectAllBkzy() {
      const checkboxes = document.getElementsByName('benke_zhuanye');
      checkboxes.forEach(checkbox => checkbox.checked = true);
    }

    function clearAllBkzy() {
      const checkboxes = document.getElementsByName('benke_zhuanye');
      checkboxes.forEach(checkbox => checkbox.checked = false);
    }
  </script>
</body>

</html>